<template>
  <div class="header-view">
    <div class="logo-container">
      <div class="logo" @click="goHome">
        <img src="@/assets/images/logo.png" alt="小红书" class="logo-image" />
      </div>
    </div>
    
    <div class="search-container">
      <div class="search-wrapper">
        <el-input 
          placeholder="搜索小红书" 
          v-model="searchText"
          class="search-input"
          type="search"
          @keyup.enter="handleSearch"
        >
          <template #prefix>
            <el-icon class="search-icon"><Search /></el-icon>
          </template>
        </el-input>
      </div>
    </div>
    
    <div class="header-links">
      <el-link 
        v-for="link in links" 
        :key="link.key"
        class="header-link"
        @click="() => handleLinkClick(link.key)"
      >
        {{ link.label }}
      </el-link>
    </div>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { Search } from '@element-plus/icons-vue'

const props = defineProps({
  modelValue: {
    type: String,
    default: ''
  }
})

const emit = defineEmits(['update:modelValue', 'search', 'link-click'])

const router = useRouter()

const searchText = ref(props.modelValue)

const links = ref([
  { key: 'creation', label: '创作中心' },
  { key: 'business', label: '业务合作' }
])

// 监听props变化更新searchText
watch(() => props.modelValue, (newVal) => {
  searchText.value = newVal
})

const handleSearch = () => {
  emit('update:modelValue', searchText.value)
  emit('search', searchText.value)
}

const handleLinkClick = (key) => {
  emit('link-click', key)
}

const goHome = () => {
  router.push('/')
}
</script>

<style lang="scss" scoped>
.header-view {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 0 80px;
}

.logo-container {
  width: 240px;
  
  .logo {
    cursor: pointer;
    display: flex;
    align-items: center;
    
    .logo-image {
      height: 40px;
      width: auto;
    }
  }
}

.search-container {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 40px;
  
  .search-wrapper {
    position: relative;
    width: 480px;
    max-width: 100%;
    
    .search-input {
      :deep(.el-input__wrapper) {
        background-color: #f5f5f5;
        border: none;
        border-radius: 20px;
        box-shadow: none;
        padding: 4px 16px;
        
        &:hover {
          background-color: #f0f0f0;
        }
        
        &.is-focus {
          background-color: white;
          box-shadow: 0 0 0 1px #ff2442;
        }
      }
      
      :deep(.el-input__inner) {
        height: 36px;
        line-height: 36px;
        font-size: 14px;
        color: #333;
        
        &::placeholder {
          color: #999;
        }
      }
      
      :deep(.el-input__prefix) {
        color: #999;
      }
    }
    
    .search-icon {
      font-size: 16px;
    }
  }
}

.header-links {
  display: flex;
  gap: 32px;
  margin-left: auto;
  
  .header-link {
    font-size: 14px;
    color: #333;
    text-decoration: none;
    white-space: nowrap;
    
    &:hover {
      color: #ff2442;
    }
  }
}
</style>